package com.dhcc.sds.busi.controller;

import com.alibaba.fastjson.JSONArray;
import com.dhcc.cdc.busi.service.ICdcHospitalService;
import com.dhcc.cdc.busi.service.ICdcLocationService;
import com.dhcc.cdc.busi.service.ICdcUserService;
import com.dhcc.sds.base.service.ISdsCommonService;
import com.dhcc.sds.base.service.ISdsQcentityService;
import com.dhcc.sds.busi.service.IAnalysisSdsIndstaService;
import com.dhcc.sds.busi.service.ISdsQcincaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 单病种质量指标统计
 *
 * @ClassName: AnalysisSdsIndexstaController
 * @Description: TODO
 * @author zhangdc
 * @date 2021-08-08 10:09:15
 */
@Controller
@RequestMapping("${sys.backendPath}/analysis/indexstat")
public class AnalysisSdsIndexstaController {

    private String PREFIX = "/backend/sds/indexstat/";

    @Autowired
    private ICdcHospitalService cdcHospitalService;

    @Autowired
    private ICdcLocationService cdcLocationService;

    @Autowired
    private ISdsQcentityService sdsQcentityService;

    @Autowired
    private IAnalysisSdsIndstaService analysisSdsIndstaService;

    @Autowired
    private ISdsQcincaseService sdsQcincaseService;

    @Autowired
    private ISdsCommonService sdsCommonService;
    @Autowired
    private ICdcUserService cdcUserService;

    /**
     * @Description: 单病种病种指标统计
     * @Title: sdsMsta
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("")
    public String index(Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        //JSONArray departMap = cdcLocationService.getDepartMap();
        //加载用户关联科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("hospitalId",sdsCommonService.getHospIdBySysUser());
        return PREFIX + "indexstat.html";
    }

    /**
     * @Description: 查询单病种费用/住院日
     * @Title: selectSysSumChart
     * @return: Object
     * @author: zhangdc
     * @date:2022-03-23 10:09:15
     */
    @RequestMapping("selectSysSumChart")
    @ResponseBody
    public Object selectSysSumChart(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectSysSumChart(params);
    }

    /**
     * @Description: 查询单病种指标统计表格数据
     * @Title: selectIndexTableData
     * @return: Object
     * @author: zhangdc
     * @date:2022-03-23 10:09:15
     */
    @RequestMapping("selectIndexTableData")
    @ResponseBody
    public Object selectIndexTableData(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectIndexTableData(params);
    }


    /**
     * @Description: 单病种病种指标统计详情数据
     * @Title: detail
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("detailList")
    public String detailList(@RequestParam Map<String, Object> params, Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        //JSONArray departMap = cdcLocationService.getDepartMap();
        //加载用户关联科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        //状态
        JSONArray statusMap = sdsCommonService.getDicCodeArray("SDQCMrStatus");
        //主任医师
        JSONArray docMap = cdcUserService.getUserMap("DOCTOR5");
        //JSONObject data = analysisSdsIndstaService.selectIndexDetailTableData(params);
        String ids = (String) params.get("ids");
        String qcEntity = (String) params.get("qcEntity");
        model.addAttribute("ids", ids);
        model.addAttribute("qcEntity", qcEntity);
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("statusMap",statusMap);
        model.addAttribute("docMap",docMap);
        return PREFIX + "indexstatdetail.html";
    }

    /**
     * @Description: 查询单病种指标详情统计表格数据
     * @Title: selectIndexTableData
     * @return: Object
     * @author: zhangdc
     * @date:2022-03-23 10:09:15
     */
    @RequestMapping("selectIndexDetailTableData")
    @ResponseBody
    public Object selectIndexDetailTableData(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectIndexDetailTableData(params);
    }

    /**
     * @Description: 查询单病种质量绩效统计
     * @Title: selectSdsMsta
     * @return: Object
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("selectSdsIndsta")
    @ResponseBody
    public Object selectSdsIndsta(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectIndexDetailTableData(params);
    }

    /**
     * @Description: 单病种病种详情指标统计
     * @Title: sdsMsta
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("detail")
    public String detail(@RequestParam Map<String, Object> map,Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        //获取病种的年份
        JSONArray yearMap = sdsQcincaseService.getYearMap();
        //获取病种的月份
        JSONArray monthMap = sdsQcincaseService.getMonthMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("yearMap",yearMap);
        model.addAttribute("monthMap",monthMap);
        model.addAttribute("dishDate", map.get("dishDate"));
        model.addAttribute("qcEntityV", map.get("qcEntity"));
        model.addAttribute("qcYearV", map.get("qcYear"));
        model.addAttribute("qcMonthV", map.get("qcMonth"));
        model.addAttribute("officeV", map.get("office"));
        model.addAttribute("departV", map.get("depart"));
        model.addAttribute("qcEntityDescV", map.get("qcEntityDesc"));
        return PREFIX + "sdsindstadetail.html";
    }

    /**
     * @Description: 查询单病种质量绩效统计
     * @Title: selectSdsMsta
     * @return: Object
     * @author: zhangdc
     * @date:2021-06-27 10:09:15
     */
    @RequestMapping("selectSdsIndstaDetail")
    @ResponseBody
    public Object selectSdsIndstaDetail(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectSdsIndstaDetail(params);
    }


    @RequestMapping("test")
    public String test(Model model) {
        //获取部门信息
        JSONArray officMap = cdcHospitalService.getOfficeMap();
        //默认加载所有科室
        JSONArray departMap = sdsCommonService.getDepartMap(new HashMap<>());
        //获取病种
        JSONArray entityMap = sdsQcentityService.getUpEntityMap();
        //获取病种的年份
        JSONArray yearMap = sdsQcincaseService.getYearMap();
        //获取病种的月份
        JSONArray monthMap = sdsQcincaseService.getMonthMap();
        model.addAttribute("officeMap",officMap);
        model.addAttribute("departMap",departMap);
        model.addAttribute("entityMap",entityMap);
        model.addAttribute("yearMap",yearMap);
        model.addAttribute("monthMap",monthMap);
        return PREFIX + "sdsindstatest.html";
    }

    @RequestMapping("selectSdsIndColumns")
    @ResponseBody
    public Object selectSdsIndColumns(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectSdsIndColumns2(params);
    }

    @RequestMapping("selectSdsIndDetailColumns")
    @ResponseBody
    public Object selectSdsIndDetailColumns(@RequestParam Map<String, Object> params) {
        return analysisSdsIndstaService.selectSdsIndDetailColumns(params);
    }

    /**
     * @Description: 查询单病种指标统计图形数据
     * @Title: selectSdsChartDatas
     * @return: Object
     * @author: zhangdc
     * @date:2021-09-27 10:09:15
     */
    @RequestMapping("selectSdsChartDatas")
    @ResponseBody
    public Object selectSdsChartDatas(@RequestParam Map<String, Object> params) {
        // 查询登录用户关联科室
        List<String> deptIds = sdsCommonService.getDeptIdsBySysUser();
        params.put("userLinkDepts", deptIds);
        return analysisSdsIndstaService.selectSdsChartDatas(params);
    }
}
